@import "frappe/public/scss/website/variables";

body {
	--icon-stroke: var(--text-color);

	--editor-line-no-bg-color: var(--gray-100);
}

body.dark {
	--editor-line-no-bg-color: var(--gray-800);
	--control-bg-on-gray: var(--gray-700);

	.draft-wiki-page {
		background: var(--gray-700);
		color: var(--gray-50);
	}
}

.form-control {
	background-color: white;
}

// edit page

.remove-sidebar-item {
	cursor: pointer;
	margin: 0 1rem 0 auto;
}

.collapsible .remove-sidebar-item {
	margin-right: calc(15px - 0.5rem);
	margin-bottom: 3px;
}

.trash-icon {
	visibility: hidden;
}

.sidebar-item:hover .trash-icon,
.sidebar-group .collapsible:hover .trash-icon {
	visibility: visible;
}

$font-sizes-desktop: (
	"sm": 0.75rem,
	"base": 1rem,
	"lg": 1.125rem,
	"xl": 1.41rem,
	"2xl": 1.6rem,
	"3xl": 2rem,
);

$font-sizes-mobile: (
	"sm": 0.75rem,
	"base": 1rem,
	"lg": 1.125rem,
	"xl": 1.25rem,
	"2xl": 1.5rem,
	"3xl": 1.75rem,
);

.wiki-editor,
.from-markdown {
	margin: auto;
}

.wiki-editor,
.wiki-content {
	font-size: map-get($font-sizes-desktop, "base");
	color: var(--editor-button-text-color);
	line-height: 1.7;
	max-width: calc(100vw - 6rem);

	a:not(.dropdown-item, .btn) {
		color: var(--text-color);
		text-decoration: underline;
	}

	p {
		color: var(--text-color);
	}

	ul,
	ol {
		padding-left: 2rem;
	}

	ul {
		list-style-type: disc;
	}

	ol {
		list-style: decimal;
	}

	li {
		color: var(--text-color);
		padding-top: 1px;
		padding-bottom: 1px;

		&::marker {
			color: var(--text-color);
		}

		p {
			margin-bottom: 0;
		}
	}

	li > ul,
	li > ol {
		padding-left: 1.5rem;
	}

	ul > li:first-child {
		margin-top: 3px !important;
	}

	ul > * + *,
	ol > * + * {
		margin-top: 2px !important;
	}

	blockquote {
		padding: 0.75rem 1rem 0.75rem 1.25rem;
		font-size: $font-size-sm;
		font-weight: 500;
		border: 1px solid var(--bqoute-border-color);
		border-left: 5px solid var(--bqoute-border-color);
		border-radius: 0.5rem;
		margin: 1.5rem 0 !important;
		background-color: var(--bqoute-bg-color);
	}

	blockquote p:last-child {
		margin-bottom: 0 !important;
	}

	b,
	strong {
		color: $gray-800;
		font-weight: 600;
	}

	h1,
	h2,
	h3,
	h4,
	h5,
	h6 {
		color: $gray-900;
	}

	h2,
	h3,
	h4,
	h5,
	h6 {
		font-weight: 600;
	}

	h1 {
		font-size: map-get($font-sizes-desktop, "3xl");
		line-height: 1.5;
		font-weight: 600;

		// for byline
		& + p {
			margin-top: 1rem !important;
			line-height: 1.4;
		}
	}

	& > p {
		margin-top: 1rem !important;
	}

	h2 {
		font-size: map-get($font-sizes-mobile, "2xl");
		line-height: 1.56;
		margin: 3rem 0 1rem !important;

		@include media-breakpoint-up(md) {
			font-size: map-get($font-sizes-desktop, "2xl");
		}
	}

	h3 {
		font-size: map-get($font-sizes-mobile, "xl");
		line-height: 1.56;
		margin: 2rem 0 1rem !important;

		@include media-breakpoint-up(md) {
			font-size: map-get($font-sizes-desktop, "xl");
		}
	}

	h4 {
		font-size: map-get($font-sizes-mobile, "lg");
		line-height: 1.56;
		margin-top: 1.25rem !important;
	}

	h5:not(.modal-title) {
		font-size: map-get($font-sizes-mobile, "base");
		line-height: 1.5;
		font-weight: 600;
		margin-top: 1rem !important;
	}

	h6 {
		font-size: map-get($font-sizes-mobile, "sm");
		line-height: 1.35;
		font-weight: 600;
		text-transform: uppercase;
		margin-top: 1rem !important;
	}

	tr > td,
	tr > th {
		font-size: $font-size-sm;
		padding: 0.5rem;
	}

	th:empty {
		display: none;
	}

	.screenshot {
		border: 1px solid $gray-400;
		border-radius: 0.375rem;
		margin-top: 0.5rem !important;
	}

	.screenshot + em {
		text-align: center;
		display: block;
		margin-top: 0.5rem !important;
		margin-bottom: 2rem !important;
	}

	p > code:not(.hljs) {
		padding: 0 0.25rem;
		background-color: var(--code-bg-color);
		color: var(--code-text-color);
		border-radius: 0.125rem;
	}

	table {
		border-color: $gray-200;
		border-collapse: collapse;
		table-layout: fixed;
		width: 100%;
		margin: 0;
		overflow: hidden;

		td,
		th {
			min-width: 1em;
			border: 2px solid #ced4da;
			padding: 3px 5px;
			vertical-align: top;
			box-sizing: border-box;
			position: relative;

			> * {
				margin-bottom: 0;
			}
		}

		th {
			font-weight: bold;
			text-align: left;
			background-color: var(--active-item-color);
		}

		.selectedCell:after {
			z-index: 2;
			position: absolute;
			content: "";
			left: 0;
			right: 0;
			top: 0;
			bottom: 0;
			background: rgba(200, 200, 255, 0.4);
			pointer-events: none;
		}

		.column-resize-handle {
			position: absolute;
			right: -2px;
			top: 0;
			bottom: -2px;
			width: 4px;
			background-color: #adf;
			pointer-events: none;
		}

		p {
			margin: 0;
		}
	}

	.table-bordered,
	.table-bordered th,
	.table-bordered td {
		border-left: none;
		border-right: none;
		border-color: $gray-200;
	}

	.table-bordered thead th,
	.table-bordered thead td {
		border-bottom-width: 1px;
	}

	pre {
		margin: 1rem 0;
		background: #011627;
		color: #d6deeb;
		border-radius: 0.5rem;
		overflow: hidden;
		position: relative;

		&:hover .copy-btn {
			visibility: visible;
		}

		.copy-btn {
			visibility: hidden;
			right: 0.5rem;
			padding: 0.75rem;
			position: absolute;
			background-color: inherit;

			&:hover {
				color: var(--gray-500);
				background-color: inherit;
				border-color: inherit;
			}

			&:focus {
				box-shadow: none;
			}
		}

		code {
			overflow-x: auto;
			color: inherit;
			background: none !important;

			del {
				&.diffmod,
				&.diffdel {
					background-color: #8b0000;
				}
			}

			ins {
				&.diffmod,
				&.diffins {
					background-color: #006400;
				}
			}
		}
	}

	hr {
		border-top: 1px solid $gray-200;
	}
}

.wiki-editor {
	margin-left: -1rem;
	width: 800px;

	@include media-breakpoint-down(md) {
		margin: 0;
		width: 100%;
		max-width: none;
	}

	pre {
		padding: 0.75rem 1rem;
	}

	h1 {
		font-size: 24px;
		font-weight: 600;
		line-height: 28px;
		letter-spacing: 0.005em;
		text-align: left;
		margin-top: 0.75rem;
	}

	h2 {
		margin-top: 2.5rem;
		font-size: 20px;
		font-weight: 600;
		line-height: 23px;
		letter-spacing: 0.01em;
		text-align: left;
	}

	h3 {
		font-size: 16px;
		font-weight: 600;
		line-height: 18px;
		letter-spacing: 0.015em;
		text-align: left;
	}

	p {
		font-size: 15px;
		font-weight: 420;
		line-height: 155%;
		letter-spacing: 0.02em;
		text-align: left;
	}

	button:not(.btn-primary) {
		all: unset;
		cursor: pointer;
		margin: 0 0.25rem;
		border-radius: 0.25rem;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 2rem;
		height: 1.75rem;
	}

	a.btn-primary-light {
		background-color: var(--btn-secondary-color) !important;
	}

	button:hover {
		background-color: var(--editor-hover-button-color);
	}

	.is-active {
		background-color: var(--editor-hover-button-color) !important;
	}

	.dropdown {
		display: inline-block;

		#dropdownMenuButton::after {
			display: none;
		}
	}

	.ProseMirror {
		height: 80vh;
		overflow-y: auto;
		padding: 0 1rem;
		padding-right: 120px;

		@include media-breakpoint-down(md) {
			padding-right: 1rem;
			width: 92vw;
		}

		.is-empty::before {
			content: attr(data-placeholder);
			float: left;
			color: #ced4da;
			pointer-events: none;
			height: 0;
		}

		&:focus-visible {
			outline: none;
		}
	}

	img.ProseMirror-selectednode {
		border: 2px solid #7cbcf5;
	}

	> :last-child {
		overflow: auto;
		margin-top: 0 !important;
		border: 1px solid $gray-200;
		border-radius: 0.5rem;
	}

	> :first-child {
		padding-bottom: 0.5rem;
		display: flex;
		flex-wrap: wrap;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		width: 800px;

		@include media-breakpoint-down(md) {
			width: 100%;
			flex-wrap: nowrap;
			align-items: flex-start;
		}

		.wiki-edit-controls {
			flex-wrap: wrap;
			display: inline-flex;
			row-gap: 0.5rem;
		}

		.wiki-edit-control-btn {
			margin-left: auto;
			display: inline-flex;

			> * {
				margin: 0.5rem 0.25rem;
			}

			@include media-breakpoint-down(md) {
				margin-left: 0;
				flex-direction: column;
				align-items: flex-start;
			}
		}
	}
}

.wiki-content {
	min-height: 55vh;

	@include media-breakpoint-down(md) {
		max-width: calc(100vw - 3rem);
	}

	div > p:first-child {
		margin-top: 1.5rem !important;
		line-height: 1.4;
	}

	code {
		padding: 0.75rem 1rem;
	}

	// tiptap task-list
	ul[data-type="taskList"] p {
		margin: 0 !important;
	}
}

// button
.btn:hover {
	color: #000;
	background-color: #f9fafb;
	border-color: #f9fafb;
}

.btn.btn-primary:hover {
	color: #fff;
	background-color: #383838;
	border-color: #383838;
}

// tiptap task-list
ul[data-type="taskList"] {
	list-style: none;
	padding: 0;

	p {
		margin: 0;
	}

	li {
		display: flex;

		> label {
			flex: 0 0 auto;
			margin-right: 0.25rem;
			margin-bottom: 0;
			user-select: none;
		}

		> div {
			flex: 1 1 auto;
		}

		ul li,
		ol li {
			display: list-item;
		}

		ul[data-type="taskList"] > li {
			display: flex;
		}

		input {
			color: #000;
			margin: 0.1rem;
			margin-top: 0.4rem;
			border: 1px solid var(--gray-500);
			accent-color: black;

			&:checked {
				background-color: var(--primary);
				background-image: url("data:image/svg+xml, <svg viewBox='0 0 8 7' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M1 4.00001L2.66667 5.80001L7 1.20001' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>"),
					var(--checkbox-gradient);
				background-size: 57%, 100%;
				box-shadow: none;
				border: none;
			}
		}
	}
}
